package com.usian.controller;

import com.usian.feign.ContentServiceFeign;
import com.usian.pojo.TbContentCategory;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author chen
 * @date 2021/1/11 - 17:04 - 星期一
 * @project usian_parent
 * @package com.usian.controller
 * @by GGbomd猪猪侠
 */
@RestController
@RequestMapping("/content")
public class ContentCategoryControllerWeb {

    @Autowired
    private ContentServiceFeign contentServiceFeign;

    /**
     * 根据父节点查询子节点
     * @param id
     * @return
     */
    @RequestMapping("/selectContentCategoryByParentId")
    public Result selectContentCategoryByParentId(@RequestParam(defaultValue = "0") Long id){
        List<TbContentCategory> tbContentCategories = contentServiceFeign.selectContentCategoryByParentId(id);
        if (tbContentCategories != null && tbContentCategories.size() > 0){
            return Result.ok(tbContentCategories);
        }
        return Result.error("查无结果");
    }

    /**
     * 内容分类添加操作 tb_content_category
     * @param tbContentCategory
     * @return
     */
    @RequestMapping("/insertContentCategory")
    public Result insertContentCategory(TbContentCategory tbContentCategory){
        Integer integer = contentServiceFeign.insertContentCategory(tbContentCategory);
        if (integer == 1){
            return Result.ok();
        }
        return Result.error("添加失败");
    }

    /**
     * 删除内容分类
     * @param categoryId
     * @return
     */
    @RequestMapping("/deleteContentCategoryById")
    public Result deleteContentCategoryById(@RequestParam("categoryId") Long categoryId){
        Integer integer = contentServiceFeign.deleteContentCategoryById(categoryId);
        if (integer == 1){
            return Result.ok();
        }
        return Result.error("删除失败");
    }

    /**
     * 修改内容分类
     * @param id
     * @param name
     * @return
     */
    @RequestMapping("/updateContentCategory")
    public Result updateContentCategory(Long id ,String name){
        Integer integer = contentServiceFeign.updateContentCategory(id, name);
        if (integer == 1){
            return Result.ok();
        }
        return Result.error("修改失败");
    }
}
